
package com.ukao.steward.pesenter.valetRunners;

import com.ukao.steward.base.BasePresenter;
import com.ukao.steward.bean.TodayEarningBean;
import com.ukao.steward.consts.Constant;
import com.ukao.steward.consts.SaveParams;
import com.ukao.steward.retrofit.ApiCallback;
import com.ukao.steward.util.L;
import com.ukao.steward.view.valetRunners.TodayEarningsView;

import java.util.HashMap;

import rx.Observable;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class TodayEarningsPesenter extends BasePresenter<TodayEarningsView> {


    public TodayEarningsPesenter(TodayEarningsView view) {
        attachView(view);
    }





    /**
     我的收入
     */
    public void  myIncome( String  data,String   type) {
        mvpView.showLoading();
        HashMap mHashMap = new HashMap<String, String>();
        mHashMap.put("date",data);
        mHashMap.put("accessToken", SaveParams.getToken());
        Observable  mObservable=null;
        if (type.equals("1")){
            mObservable=apiStores.dayIncome(Constant.createParameter(mHashMap));
        }else{
            mObservable=apiStores.monthIncome(Constant.createParameter(mHashMap));
        }
        L.i("mHashMap="+mHashMap.toString());
        addSubscription(mObservable,
                new ApiCallback<TodayEarningBean>() {
                    @Override
                    public void onSuccess(TodayEarningBean model) {

                        if (model.getHttpCode() == 200) {
                            mvpView.todayEarningSucceed(model.getData());


                        }else{

                            mvpView.showError(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {

                        mvpView.hideLoading();

                    }
                });

    }


}
